package com.xiaozhichao.databafflesys.common.domain;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

public class ResultVo {
	private String code;
	private String msg;
	private Long count;
	private Object data;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Long getCount() {
		return count;
	}

	public void setCount(Long count) {
		this.count = count;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public ResultVo(String code, String msg, Long count, Object data) {
		super();
		this.code = code;
		this.msg = msg;
		this.count = count;
		this.data = data;
	}

	public static ResultVo getResult(ExceptionEnums exceptionEnums, Long count, Object data) {
		ResultVo responseVo = new ResultVo();
		responseVo.setCode(exceptionEnums.getCode());
		responseVo.setMsg(exceptionEnums.getMsg());
		responseVo.setCount(count);
		responseVo.setData(data);
		return responseVo;
	}

	public static ResultVo getResult(ExceptionEnums exceptionEnums, Object data) {
		ResultVo responseVo = new ResultVo();
		responseVo.setCode(exceptionEnums.getCode());
		responseVo.setMsg(exceptionEnums.getMsg());
		responseVo.setCount(0L);
		responseVo.setData(data);
		return responseVo;
	}

	public static ResultVo getResult(String code, String msg) {
		ResultVo responseVo = new ResultVo();
		responseVo.setCode(code);
		responseVo.setMsg(msg);
		responseVo.setCount(0L);
		responseVo.setData(new JSONObject());
		return responseVo;
	}
	
	public static ResultVo getResult(ExceptionEnums exceptionEnums, String msg) {
		ResultVo responseVo = new ResultVo();
		responseVo.setCode(exceptionEnums.getCode());
		if (StringUtils.isEmpty(msg)) {
			responseVo.setMsg(exceptionEnums.getMsg());
		}else {
			responseVo.setMsg(msg);
		}
		responseVo.setCount(0L);
		responseVo.setData(msg);
		return responseVo;
	}

	public static ResultVo getResult(ExceptionEnums exceptionEnums) {
		ResultVo responseVo = new ResultVo();
		responseVo.setCode(exceptionEnums.getCode());
		responseVo.setMsg(exceptionEnums.getMsg());
		responseVo.setCount(0L);
		responseVo.setData(new JSONObject());
		return responseVo;
	}

	public ResultVo() {
		super();
	}

	@Override
	public String toString() {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("code", code);
		jsonObject.put("msg", msg);
		jsonObject.put("count", count);
		jsonObject.put("data", data);
		return jsonObject.toString();
	}

}